package wnhz.com.business.groupshop.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseFragment;
import wnhz.com.business.base.BaseRVAdapter;
import wnhz.com.business.base.BaseViewHolder;
import wnhz.com.business.groupshop.bean.HotSeachBean;

/**
 * Created by Administrator on 2017/9/13 0013.
 */

public class ShaiXuanFragment extends BaseFragment {

    @BindView(R.id.recycler_pinpai)
    RecyclerView recyclerPinpai;
    @BindView(R.id.recycler_zhekou)
    RecyclerView recyclerZhekou;
    @BindView(R.id.edt_lowpriace)
    EditText edtLowpriace;
    @BindView(R.id.edt_highpriace)
    EditText edtHighpriace;
    @BindView(R.id.tv_place)
    TextView tvPlace;
    @BindView(R.id.tv_resetplace)
    TextView tvResetplace;
    @BindView(R.id.ll_orderhot)
    LinearLayout llOrderhot;
    @BindView(R.id.ll_caizhi)
    LinearLayout llCaizhi;
    @BindView(R.id.tv_reset)
    TextView tvReset;
    @BindView(R.id.tv_makesure)
    TextView tvMakesure;
    Unbinder unbinder;
    private View view;



    private HotSeachBean hotSeachBean;
    private List<HotSeachBean> itempinpai = new ArrayList<>();
    private List<HotSeachBean> itemzhekou = new ArrayList<>();





    public static ShaiXuanFragment newInstance() {
        return new ShaiXuanFragment();
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_shaixuan, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initview();
        setRecyclerPinpai();
        setRecyclerZhekou();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    private void initview()
    {
        recyclerPinpai.setLayoutManager(new GridLayoutManager(getContext(),4,LinearLayoutManager.VERTICAL,false));
        recyclerZhekou.setLayoutManager(new GridLayoutManager(getContext(),4,LinearLayoutManager.VERTICAL,false));
        itempinpai.clear();
        itempinpai.add(new HotSeachBean("李维斯"));
        itempinpai.add(new HotSeachBean("李宁"));
        itempinpai.add(new HotSeachBean("纽乐图"));
        itempinpai.add(new HotSeachBean("花花公子"));
        itempinpai.add(new HotSeachBean("耐克"));
        itempinpai.add(new HotSeachBean("安迪达斯"));
        itempinpai.add(new HotSeachBean("公爵车"));

        itemzhekou.clear();
        itemzhekou.add(new HotSeachBean("包邮"));
        itemzhekou.add(new HotSeachBean("货到付款"));
        itemzhekou.add(new HotSeachBean("分期付款"));
        itemzhekou.add(new HotSeachBean("全球购"));
        itemzhekou.add(new HotSeachBean("运费险"));
    }


    private void setRecyclerPinpai()
    {
        recyclerPinpai.setAdapter(new BaseRVAdapter(getContext(),itempinpai) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_hotseach_head;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getTextView(R.id.tv_name).setText(itempinpai.get(position).getName());
                final String names =  holder.getTextView(R.id.tv_name).getText()+"";
                holder.getTextView(R.id.tv_name).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        startActivityForResult(new Intent().putExtra("types",names),0);
                    }
                });
            }

        });
    }
    private void setRecyclerZhekou()
    {
        recyclerZhekou.setAdapter(new BaseRVAdapter(getContext(),itemzhekou) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_hotseach_head;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getTextView(R.id.tv_name).setText(itemzhekou.get(position).getName());
                final String names =  holder.getTextView(R.id.tv_name).getText()+"";
                holder.getTextView(R.id.tv_name).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        startActivityForResult(new Intent().putExtra("types",names),0);
                    }
                });
            }

        });
    }

    @OnClick({R.id.tv_place, R.id.tv_resetplace, R.id.ll_orderhot, R.id.ll_caizhi, R.id.tv_reset, R.id.tv_makesure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //定位地方
            case R.id.tv_place:
                break;
            //重新定位
            case R.id.tv_resetplace:
                break;
            //订购热点
            case R.id.ll_orderhot:
                break;
            //材质
            case R.id.ll_caizhi:
                break;
            //重置
            case R.id.tv_reset:
                edtLowpriace.setText("");
                edtHighpriace.setText("");
                break;
            //确定
            case R.id.tv_makesure:
                break;
        }
    }
}
